package com.entrogy.bean;

import java.util.List;
import java.util.Map;

/**
 * @Author 许红松
 * @date 2019/4/28 0028 上午 8:43
 */
public class PageBean<T> {

    // 传递的参数或是配置的参数
    private int currentPage; // 当前页
    private int pageSize; // 每页显示多少条记录

    // 查询数据库
    private List<T> list1;; // 本页的数据列表
    private int Counts; // 总记录数

    // 计算
    private int pageCount; // 总页数
    private int beginPageIndex; // 页码列表的开始索引（包含）
    private int endPageIndex; // 页码列表的结束索引（包含）

    private String baseImage;//图片存储路径的form bean

    public PageBean() {
        super();
    }

    /**
     * 只接受4个必要的属性，会自动的计算出其他3个属性的值
     *
     * @param currentPage
     * @param pageSize
     * @param list1
     * @param Counts
     */
    public PageBean(int currentPage, int pageSize, List<T> list1, int Counts) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list1 = list1;
        this.Counts = Counts;

            // 计算 pageCount
        pageCount = (Counts + pageSize - 1) / pageSize;

        // 计算 beginPageIndex 与 endPageIndex
         // >> 总页码小于等于10页时，全部显示
        if (pageCount <= 10) {
            beginPageIndex = 1;
            endPageIndex = pageCount;
        }
           // >> 总页码大于10页时，就只显示当前页附近的共10个页码
        else {
          // 默认显示 前4页 + 当前页 + 后5页
            beginPageIndex = currentPage - 4; // 7 - 4 = 3;
            endPageIndex = currentPage + 5; // 7 + 5 = 12; --> 3 ~ 12

// 如果前面不足4个页码时，则显示前10页
            if (beginPageIndex < 1) {
                beginPageIndex = 1;
                endPageIndex = 10;
            }
// 如果后面不足5个页码时，则显示后10页
            else if (endPageIndex > pageCount) {
                endPageIndex = pageCount;
                beginPageIndex = pageCount - 9;
            }
        }
    }

    public List<T> getList1() {
        return list1;
    }

    public void setList1(List<T> list1) {
        this.list1 = list1;
    }

    public int getCounts() {
        return Counts;
    }

    public void setCounts(int counts) {
        Counts = counts;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }



    public int getBeginPageIndex() {
        return beginPageIndex;
    }

    public void setBeginPageIndex(int beginPageIndex) {
        this.beginPageIndex = beginPageIndex;
    }

    public int getEndPageIndex() {
        return endPageIndex;
    }

    public void setEndPageIndex(int endPageIndex) {
        this.endPageIndex = endPageIndex;
    }

    public String getBaseImage() {
        return baseImage;
    }

    public void setBaseImage(String baseImage) {
        this.baseImage = baseImage;
    }

    public PageBean<T> pageBeans(List<T> list1, int  Counts,String baseImage){
        PageBean<T> pageBean=new   PageBean<>();
        pageBean.setList1(list1);
        pageBean.setCounts(Counts);
        pageBean.setBaseImage(baseImage);
        return pageBean;
    }
    public PageBean<T> pageBeans(List<T> list1, int  Counts){
        PageBean<T> pageBean=new   PageBean<>();
        pageBean.setList1(list1);
        pageBean.setCounts(Counts);
        return pageBean;
    }
}
